<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ui="http://java.sun.com/jsf/facelets"
      template="/resources/template/template.xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>

        <ui:composition 
            template="/resources/template/template.xhtml" >

            <ui:define name="content">
                <h:form>


                    <p:panel header="Channel Schedule Management" >


                        <table style="width: 100%;"  class="alignTop" >
                            <tr>
                                <td style="width: 30%;">

                                    <p:panel header="Select Session" style="min-width: 500px;height: 520px; width: 30%;">
                                        <h:panelGrid columns="2">
                                            <h:outputLabel  value="Speciality" ></h:outputLabel>
                                            <p:autoComplete  forceSelection="true" value="#{sheduleController.speciality}" id="acSpeciality" placeholder="Speciality"
                                                             completeMethod="#{doctorSpecialityController.completeSpeciality}" var="mysp" itemLabel="#{mysp.name}" itemValue="#{mysp}"
                                                             converter="specilityCon"   >
                                                <f:ajax event="itemSelect" execute="acSpeciality" render="scStaff"  />
                                            </p:autoComplete>



                                            <h:outputLabel  value="Doctor" ></h:outputLabel>
                                            <p:autoComplete   forceSelection="true" value="#{sheduleController.currentStaff}" id="scStaff" placeholder="Doctor"
                                                              completeMethod="#{sheduleController.completeStaff}" var="mys" itemLabel="#{mys.person.nameWithTitle}" itemValue="#{mys}"
                                                              converter="stfcon"   >   
                                                <f:ajax event="itemSelect" execute="scStaff" render="lstSelect gpDetail" listener="#{sheduleController.prepareAdd()}" />
                                            </p:autoComplete>  



                                            <h:outputLabel  value="Sessions" ></h:outputLabel>
                                            <h:panelGrid id="gpSelectText" >
                                                <p:selectOneListbox  id="lstSelect" converter="sscon"    value="#{sheduleController.current}" style="width: 400px; height: 250px;"  >
                                                    <f:selectItems  value="#{sheduleController.items}" var="myItem" itemValue="#{myItem}" itemLabel="#{myItem.name}" ></f:selectItems>
                                                    <f:ajax render="gpDetail" execute="lstSelect" event="click" listener="#{sheduleController.fillFees()}" >
                                                    </f:ajax>
                                                </p:selectOneListbox>
                                            </h:panelGrid>

                                        </h:panelGrid>







                                        <h:panelGrid id="gpSelectButtons" columns="3"  >                     
                                            <p:commandButton ajax="false" id="btnAdd" value="Add New Session" 
                                                             action="#{sheduleController.prepareAdd()}" 
                                                             styleClass="buttons" onclick="onSubmitButton();" >
                                                <f:ajax render="btnAdd  btnDelete btnSave lstSelect gpDetail" execute="" >
                                                </f:ajax>
                                            </p:commandButton>
                                            <p:commandButton ajax="false" id="btnDelete" onclick="if (!confirm('Are you sure you want to delete this record?'))
                                                        return false;" action="#{sheduleController.delete()}"  value="Delete Selected Session" disabled="#{!webUserController.hasPrivilege('ChannellingChannelShedulRemove')}" >
                                            </p:commandButton>
                                        </h:panelGrid>
                                        <p:panelGrid columns="1" >
                                            <f:facet name="header" >
                                                Links
                                            </f:facet>
                                            <p:commandLink value="Create Default Fee Set for Selected Sessions" action="#{sheduleController.createOnCallFeeOldSession()}" rendered="#{webUserController.hasPrivilege('Developers')}"  ajax="false" />
                                            <p:commandLink value="Manually Create Channelling Seesions For Selected Doctor" action="#{sheduleController.createFutureSessionsManually()}" rendered="#{webUserController.hasPrivilege('Developers')}"  ajax="false" />
                                        </p:panelGrid>

                                    </p:panel>

                                </td>
                                <td  style="width: 70%;">

                                    <p:panel id="gpDetail" header="Session Details" style="width: 100%; ">  
                                        <h:panelGrid columns="3" >
                                            <p:commandButton ajax="false" id="btnSave" value="Save"  
                                                             action="#{sheduleController.saveSelected}"
                                                             styleClass="buttons" onclick="onSubmitButton();">

                                            </p:commandButton>
                                            <p:commandButton value="Go To Channel Booking"
                                                             rendered="#{webUserController.hasPrivilege('Developers')}"
                                                             action="/channel/channel_booking" 
                                                             ajax="false" onclick="onSubmitButton();" />
                                        </h:panelGrid>




                                        <p:tabView style="width: 100%!important;">
                                            <p:tab title="Details">
                                                <h:panelGrid columns="2" cellpadding="10">


                                                    <p:outputLabel value="Session Name"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.name}" disabled="#{sheduleController.current.id ne null and !webUserController.hasPrivilege('ChannellingChannelShedulName')}"/>


                                                    <h:panelGroup rendered="#{sheduleController.current.id ne null}" >
                                                        <h:panelGroup rendered="#{sheduleController.current.sessionDate eq null}" >
                                                            <p:outputLabel value="Weekday"></p:outputLabel>
                                                        </h:panelGroup>
                                                        <h:panelGroup rendered="#{sheduleController.current.sessionDate ne null}" >
                                                            <p:outputLabel value="Session Date"></p:outputLabel>
                                                        </h:panelGroup>
                                                    </h:panelGroup>

                                                    <h:panelGroup rendered="#{sheduleController.current.id ne null}" >
                                                        <h:panelGroup rendered="#{sheduleController.current.sessionDate eq null}" >
                                                            <p:inputText disabled="true" value="Sunday" rendered="#{sheduleController.current.sessionWeekday eq 1 and sheduleController.current.sessionWeekday ne null}"/>
                                                            <p:inputText disabled="true"  value="Monday" rendered="#{sheduleController.current.sessionWeekday eq 2 and sheduleController.current.sessionWeekday ne null}"/>
                                                            <p:inputText disabled="true"  value="Tuesday" rendered="#{sheduleController.current.sessionWeekday eq 3 and sheduleController.current.sessionWeekday ne null}"/>
                                                            <p:inputText disabled="true"  value="Wednesday" rendered="#{sheduleController.current.sessionWeekday eq 4 and sheduleController.current.sessionWeekday ne null}"/>
                                                            <p:inputText disabled="true"  value="Thursday" rendered="#{sheduleController.current.sessionWeekday eq 5 and sheduleController.current.sessionWeekday ne null}"/>
                                                            <p:inputText disabled="true"  value="Friday" rendered="#{sheduleController.current.sessionWeekday eq 6 and sheduleController.current.sessionWeekday ne null}"/>
                                                            <p:inputText disabled="true"  value="Sutarday" rendered="#{sheduleController.current.sessionWeekday eq 7 and sheduleController.current.sessionWeekday ne null}"/>
                                                        </h:panelGroup>
                                                        <h:panelGroup rendered="#{sheduleController.current.sessionDate ne null}" >
                                                            <p:inputText disabled="true"  value="#{sheduleController.current.sessionDate}" rendered="#{sheduleController.current.sessionWeekday eq null}">
                                                                <f:convertDateTime pattern="yyyy MMM dd" />
                                                            </p:inputText>
                                                        </h:panelGroup>

                                                    </h:panelGroup>


                                                    <h:outputText value="Institution" ></h:outputText>
                                                    <p:selectOneMenu id="cmbIns" value="#{sheduleController.current.institution}" >
                                                        <f:selectItem itemLabel="Please select a Institution"/>
                                                        <f:selectItems value="#{institutionController.companies}" 
                                                                       var="cat" itemLabel="#{cat.name}" itemValue="#{cat}" />    
                                                        <f:ajax execute="cmbIns" render="cmbDep" event="change"/>
                                                    </p:selectOneMenu>



                                                    <h:outputText value="Department"></h:outputText>        
                                                    <p:selectOneMenu id="cmbDep" value="#{sheduleController.current.department}">
                                                        <f:selectItem itemLabel="Please select a Department" />
                                                        <f:selectItems value="#{sheduleController.institutionDepatrments}"
                                                                       var="dep" itemLabel="#{dep.name}" itemValue="#{dep}" />
                                                    </p:selectOneMenu>
                                                    <p:outputLabel value="Start Time"/>                        
                                                    <p:calendar  value="#{sheduleController.current.startingTime}" navigator="true" pattern="HH:mm" timeOnly="true">                            
                                                    </p:calendar>

                                                    <p:outputLabel value="End Time"/>                        
                                                    <p:calendar  value="#{sheduleController.current.endingTime}" navigator="true" pattern="HH:mm" timeOnly="true">                            
                                                    </p:calendar>

                                                    <p:outputLabel value="Starting Number"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.startingNo}" disabled="#{sheduleController.current.id ne null and !webUserController.hasPrivilege('ChannellingChannelShedulStartingNo')}"/>

                                                    <p:outputLabel value="Max Number"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.maxNo}"/>

                                                    <p:outputLabel value="Duration in Minutes"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.duration}"/>
                                                    <p:outputLabel value="Room Number"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.roomNo}" disabled="#{sheduleController.current.id ne null and !webUserController.hasPrivilege('ChannellingChannelShedulRoomNo')}"/>

                                                    <p:outputLabel value="Before Session" rendered="false"/>
                                                    <p:autoComplete rendered="false" forceSelection="true" value="#{sheduleController.current.beforeSession}" 
                                                                    completeMethod="#{sheduleController.completeSession}" var="mysp" itemLabel="#{mysp.name}" itemValue="#{mysp}"
                                                                    converter="sscon"   >                            
                                                    </p:autoComplete>
                                                    <p:outputLabel value="After Session" rendered="false"/>
                                                    <p:autoComplete  rendered="false" forceSelection="true" value="#{sheduleController.current.afterSession}" 
                                                                     completeMethod="#{sheduleController.completeSession}" var="mysp" itemLabel="#{mysp.name}" itemValue="#{mysp}"
                                                                     converter="sscon"   >   
                                                    </p:autoComplete>
                                                    <p:outputLabel value="Refundable"/>
                                                    <p:selectBooleanCheckbox value="#{sheduleController.current.refundable}"/>
                                                    <p:outputLabel value="Vatable" rendered="#{sessionController.loggedPreference.applicationInstitution eq 'Cooperative' or sessionController.loggedPreference.applicationInstitution eq 'Arogya'}" />
                                                    <p:selectBooleanCheckbox value="#{sheduleController.current.vatable}" disabled="#{!webUserController.hasPrivilege('ChannelActiveVat')}" rendered="#{sessionController.loggedPreference.applicationInstitution eq 'Cooperative'or sessionController.loggedPreference.applicationInstitution eq 'Arogya'}"/>

                                                    <p:outputLabel value="Channel Type" rendered="#{sessionController.loggedPreference.applicationInstitution eq 'Cooperative'}" />
                                                    <p:selectOneMenu id="cmbChanType" value="#{sheduleController.current.forBillType}" rendered="#{sessionController.loggedPreference.applicationInstitution eq 'Cooperative'}" >
                                                        <f:selectItem itemLabel="Please Select a Type"/>
                                                        <f:selectItems value="#{enumController.channelType}" var="t" itemLabel="#{t.label}" itemValue="#{t}" />    
                                                    </p:selectOneMenu>
                                                    <p:outputLabel value="Maximum Raw Number"></p:outputLabel>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.maxTableRows}" disabled="#{sheduleController.current.id ne null and !webUserController.hasPrivilege('ChannellingChannelShedulMaxRowNo')}"></p:inputText>




                                                </h:panelGrid>
                                            </p:tab>
                                            <p:tab title="Date Details">
                                                <h:panelGrid columns="1">
                                                    <p:tabView  >
                                                        <p:tab title="WeekDay"> 
                                                            <p:selectOneMenu id="wdate" value="#{sheduleController.current.sessionWeekday}" disabled="#{sheduleController.current.id ne null}">
                                                                <f:selectItem itemLabel="Select Week Day"/>
                                                                <f:selectItem itemValue="1" itemLabel="Sunday"/>
                                                                <f:selectItem itemValue="2" itemLabel="Monday"/>
                                                                <f:selectItem itemValue="3" itemLabel="Tuesday"/>
                                                                <f:selectItem itemValue="4" itemLabel="Wednesday"/>
                                                                <f:selectItem itemValue="5" itemLabel="Thursday"/>
                                                                <f:selectItem itemValue="6" itemLabel="Friday"/>
                                                                <f:selectItem itemValue="7" itemLabel="Sutarday"/>
                                                            </p:selectOneMenu>
                                                        </p:tab>
                                                        <p:tab title="Other Day" >
                                                            <p:calendar id="odate" value="#{sheduleController.current.sessionDate}" pattern="dd MMMM yyyy" disabled="#{sheduleController.current.id ne null}">                              
                                                            </p:calendar>
                                                        </p:tab>
                                                    </p:tabView>
                                                </h:panelGrid>
                                            </p:tab>
                                            <p:tab title="Fee Details">
                                                <p:outputLabel value="Session Value = "/>
                                                <p:outputLabel value="#{sheduleController.current.total}"/>
                                                <h:panelGrid columns="1">
                                                    <p:dataTable value="#{sheduleController.itemFees}" var="i" >
                                                        <p:column headerText="Name">
                                                            <h:outputLabel value="#{i.name}"/> 
                                                        </p:column>
                                                        <p:column headerText="Fee Type">
                                                            #{i.feeType.label}
                                                        </p:column>
                                                        <p:column headerText="For for">
                                                            <h:outputLabel rendered="#{i.speciality.name ne null}" value="#{i.speciality.name} - "></h:outputLabel>

                                                            <h:outputLabel rendered="#{i.staff.person.name ne null}"  value=" #{i.staff.person.name}"></h:outputLabel>

                                                            <h:outputLabel rendered="#{i.institution.name ne null}"  value="#{i.institution.name} - "></h:outputLabel>

                                                            <h:outputLabel rendered="#{i.department.name ne null}"  value=" #{i.department.name}"></h:outputLabel>
                                                        </p:column>
                                                        <p:column headerText="Discountable" >
                                                            Allowed
                                                            <p:selectBooleanCheckbox value="#{i.discountAllowed}" label="Allowed" ></p:selectBooleanCheckbox>
                                                        </p:column>
                                                        <p:column headerText="Local Fee">
                                                            <p:inputText value="#{i.fee}" style="width: 100px!important;"/>
                                                        </p:column>
                                                        <p:column headerText="Foriegn Fee">
                                                            <p:inputText value="#{i.ffee}" style="width: 100px!important;"/>
                                                        </p:column>
                                                    </p:dataTable>
                                                </h:panelGrid>
                                            </p:tab>
                                            <p:tab title="Aditional Details">
                                                <h:panelGrid columns="2">
                                                    <p:outputLabel value="Displaying Count"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.displayCount}"/>
                                                    <p:outputLabel value="Displaying Percent"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.displayPercent}"/>
                                                    <p:outputLabel value="Session Number"></p:outputLabel>

                                                    <p:autoComplete forceSelection="true" value="#{sheduleController.current.sessionNumberGenerator}" 
                                                                    completeMethod="#{sessionNumberGenerateConrtroller.completeSessionNumberGenerator}" 
                                                                    var="mysp" itemLabel="#{mysp.name}" itemValue="#{mysp}"
                                                                    converter="genConvert">                            
                                                    </p:autoComplete>

                                                    <p:outputLabel value="Credit Numbers"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.creditNumbers}"/>
                                                    <p:outputLabel value="Cash Numbers"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.cashNumbers}"/>
                                                    <p:outputLabel value="Agent Numbers"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.agencyNumbers}"/>
                                                    <p:outputLabel value="Reserved Numbers"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.reserveNumbers}"/>
                                                    <p:outputLabel value="Reserver Name"/>
                                                    <p:inputText autocomplete="off" value="#{sheduleController.current.reserveName}"/>


                                                </h:panelGrid>
                                            </p:tab>


                                            <p:tab title="Log">
                                                <h:panelGrid columns="2">
                                                    <p:outputLabel value="Id" rendered="#{sheduleController.current ne null}"/>
                                                    <p:outputLabel value="#{sheduleController.current.id}" rendered="#{sheduleController.current ne null}"/>


                                                    <p:outputLabel value="Created by"></p:outputLabel>
                                                    <p:outputLabel value="#{sheduleController.current.creater.webUserPerson.name}"></p:outputLabel>
                                                    <p:outputLabel value="created At"></p:outputLabel>
                                                    <p:outputLabel value="#{sheduleController.current.createdAt}">
                                                        <f:convertDateTime pattern="yyyy-MM-dd hh:mm:ss a" />
                                                    </p:outputLabel>
                                                    <p:outputLabel value="Last Editor"></p:outputLabel>
                                                    <p:outputLabel value="#{sheduleController.current.editer.webUserPerson.name}"></p:outputLabel>
                                                    <p:outputLabel value="Last Edited At"></p:outputLabel>
                                                    <p:outputLabel value="#{sheduleController.current.editedAt}">
                                                        <f:convertDateTime pattern="yyyy-MM-dd hh:mm:ss a" />
                                                    </p:outputLabel>
                                                </h:panelGrid>
                                            </p:tab>

                                        </p:tabView>

                                    </p:panel>

                                </td>
                            </tr>
                        </table>




                    </p:panel>






                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>

</html>